$(function () {
  function Pop(msg) {
    $(".pop p").html(msg);
    $(".pop").fadeIn();
    var time = 2;
    setInterval(() => {
      if (time == 0) {
        $(".pop").fadeOut();
      } else {
        time--;
      }
    }, 1000);
  }

  function readData() {
    var list = localStorage.getItem("users");
    if (list !== null) {
      return JSON.parse(list);
    } else {
      return [];
    }
  }

  function savaData(data) {
    localStorage.setItem("users", data);
  }

  var users = readData();

  var username = localStorage.getItem("nowUser");
  $(".username").html("用户名：" + username);

  var nowUser = 0;

  for (var i = 0; i < users.length; i++) {
    if (username == users[i].username) {
      nowUser = i;
    }
  }

  $(".submit").click(function () {
    // var oldpwd = $("#oldpwd").val();
    // var newpwd = $("#newpwd").val();
    // var conpwd = $("#conpwd").val();
    // if (oldpwd == users[nowUser].password) {
    //   if (newpwd == conpwd) {
    //     users[nowUser].password = conpwd;
    //     savaData(JSON.stringify(users));
    //     Pop("修改成功!");
    //   } else {
    //     Pop("两次密码不一致!");
    //   }
    // } else {
    //   Pop("原密码错误!");
    // }
    $(".wcharge").fadeIn();
  });
});
